<?php include("src/updateUser_cs.php"); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="css/style.css" rel="stylesheet" type="text/css" />
<link href='css/coolMessage.css' type='text/css' rel='stylesheet' media='screen' />
<title>Modificar Usuario :: ASSC</title>
<script language="javaScript" type="text/javascript" src="js/jquery.js"></script>
<script language="javaScript" type="text/javascript" src="js/jquery.simplemodal.js"></script>
<script language="javaScript" type="text/javascript" src="js/coolMessage.js"></script>
<script language="javascript" type="text/javascript">
	
	var displayRow = '';
	if (navigator.appName == "Netscape")
		displayRow = 'table-row';
	else if (navigator.appName.indexOf("Explorer") != -1) 
		displayRow = 'block';
	
	var cont_prev = (<?php echo $countTelephones;?>);
	var cont = cont_prev;
	var maximum = 5
	function most(){
		document.getElementById("tr_phones").style.display = displayRow;
		if (cont < maximum ){
			cont++;
			$("#div_campo").append("<div id='div_tel_number_"+cont+"'>"+cont+". <input type='text' id='tel_number_"+cont+"' name='tel_number[]' class='text_grv' size='15' maxlength='14'/> <input type='text' id='tel_ext_"+cont+"' name='tel_ext[]' class='text_grv' size='3' maxlength='5'/></div>");
		}
		if(cont >0)
			document.getElementById('btnLess').disabled = 0;
	}
	
	function less(){
		if( cont == 2 )
			document.getElementById("tr_phones").style.display = 'none';
		
		if(cont > 1 ){
			$("#div_tel_number_"+cont).remove();
			cont--;
		}   
		if(cont == 1)
			document.getElementById('btnLess').disabled = 1;
	}
	
	function showMessage(show_msg){
		switch(show_msg){
			case 1://error
				coolMessage('error',"<?php echo $_SESSION["msg_cool"];?>");
			break;
			
			case 2://alert
				coolMessage('alert',"<?php echo $_SESSION["msg_cool"];?>");
			break;
			
			case 3://information
				coolMessage('information',"<?php echo $_SESSION["msg_cool"];?>");
			break;
			
			default:
				
			break;
		}
		return false;
	}

	function validate(){
		var msg    = '';
		
		var name = document.getElementById("use_name").value;
		var lastname = document.getElementById("use_lastname").value;
		var email = document.getElementById("use_email").value;
		var login = document.getElementById("use_login").value;
		var p1 = document.getElementById("use_password").value;
		var p2 = document.getElementById("confirm").value;     
		var type = document.getElementById("use_type").value;     
		
		var login_ant = document.getElementById("login_ant").value;		
		
		if(name == '') 
			msg='- Por favor entre Nombre. <br />';
		
		if(lastname == '') 
			msg='- Por favor entre Apellido. <br />';
		
		if(email == '') 
			msg= msg+'- Por favor entre email. <br />';
		
		var a = 1
		while(a <= cont){
			var c = document.getElementById("tel_number_"+a).value
			if(c == '')
				msg += '- Por favor entre No. Telefono '+a+'. <br />';
			a++;
		}
		
		if(login == '') 
			msg= msg+'- Por favor entre login. <br />';
		else{
			if( login != login_ant ){
				var use_code = document.getElementById("use_code").value;
				jQuery.ajax({
				type: "POST",
				async : false,
				url: "userDuplicatecheck.php",
				data: 'use_login='+login+'&use_code='+use_code,
				success: function(result){
					if ( result == 1 ){
						msg += '- El login <strong>'+login+'</strong> no esta disponible.<br />';
						document.getElementById("use_login").value = login_ant;
					}
					else{
						if ( result == -1 )
							msg += 'Validation error.';					
					}
				}
				});
			}
		}
		
		if(type == '') 
			msg = msg+'- Por favor entre el tipo de usuario. <br />';	 
		
		if ( ( p1.length > 0 || p2.length > 0 ) || (login != login_ant) ){
			var espacios = false;
			var k = 0;
			
			while (!espacios && (k < p1.length)){
				if (p1.charAt(k) == " ")
					espacios = true;
				k++;
			}
			
			if (espacios)
				msg= msg+'- El password no puede contener espacios. <br />';	 
			
			if (p1.length == 0 || p2.length == 0)
				msg= msg+'- Por favor entre Password. <br />';
			
			if (p1 != p2)  
				msg= msg+'- Los campos del password no coinciden. <br />';
		}
		
		if(msg==''){
			document.getElementById('form').submit();
			return true;
		}
		else{			
			coolMessage('alert', msg);
			return false;
		}		
	}
	
	function onlyNumbers(e)
	{
	   var key;
	   if(window.event)
		  key = window.event.keyCode;   //IE
	   else
		  key = e.which;                //firefox
	   if (!( (key >= 48 && key <= 57) || key ==8 || key ==9 || key ==0 || key ==46 ))
		  return false;
	   else
		  return true;
	}	
	
</script>
</head>
<body onload="javascript: showMessage(<?php echo $show_msg;?>)">
<?php $item_select = 1; include("menu.php");?><br />
    <form name="form" id="form" method="post" action="" enctype="multipart/form-data">
    <input type="hidden" name="edit" id="edit" value="1"/>	
    <input type="hidden" name="use_code" id="use_code" value="<?php echo $data->use_code;?>" />
    <input type="hidden" name="login_ant" id="login_ant" value="<?php echo $data->use_login; ?>"/>
	<input type="hidden" name="passAnt" id="passAnt" value="<?php echo $data->use_password;?>" />
	
    <input type="hidden" name="countTelephones" id="countTelephones" value="<?php echo $countTelephones;?>" />
    <div class="content_grv">
    	<table width="90%" align="center" class="shadow">
        	<tr>
            	<td class="title">Modificar Usuario</td>
            </tr>
            <tr>
            	<td>
                	<table class="tbl_form" align="center">
                    	<tr>
                        	<td width="35%" align="right"><span class="lbl_gray">Nombre:</span></td>
                            <td width="1%">&nbsp;</td>
                            <td><input type="text" name="use_name" id="use_name" class="text_grv" size="21" maxlength="20" value="<?php echo $data->use_name;?>" /></td>
                        </tr>
                        <tr>
                        	<td align="right"><span class="lbl_gray">Apellido:</span></td>
                            <td>&nbsp;</td>
                            <td><input type="text" name="use_lastname" id="use_lastname" class="text_grv" size="21" maxlength="20" value="<?php echo $data->use_lastname;?>" /></td>
                        </tr>                        
                        <tr>
                        	<td align="right"><span class="lbl_gray">Email:</span></td>
                            <td>&nbsp;</td>
                            <td><input type="text" name="use_email" id="use_email" class="text_grv" size="41" maxlength="40" value="<?php echo $data->use_email;?>" /></td>
                        </tr>
                        <tr>
                        	<td align="right"><span class="lbl_gray">Telefono(s):</span><br /><span class="lbl_gray_small">No. Telefono + Ext</span></td>
                            <td>&nbsp;</td>
                            <td>                            	
                                1. <input type="text" name="tel_number[]" id="tel_number_1" class="text_grv" size="15" maxlength="14" value="<?php echo $telephones[0]->tel_number;?>" />
                                <input type="text" name="tel_ext[]" id="tel_ext_1" class="text_grv" size="3" maxlength="5" value="<?php echo $telephones[0]->tel_ext;?>"/>
                                <input type="button" value="+" onClick="javascript: most();" class="button_grv"/>&nbsp;
                                <input type="button" value="-" id="btnLess" onClick="javascript: less()" class="button_grv_cancel" <?php echo $disabled_less_button;?>/>
                            </td>
                        </tr>
                        <tr id="tr_phones" <?php echo $style_tr_phones;?>>
                        	<td align="right" valign="top"><span class="lbl_gray">mas Telefonos:</span></td>
                            <td>&nbsp;</td>
                            <td>
                            	<div id="div_campo">
                                	<?php for ($i=1; $i < $countTelephones; $i++){?>
										<div id="div_tel_number_<?php echo ( $i+1 );?>">
											<?php echo ( $i+1 );?>. <input type="text" id="tel_number_<?php echo ( $i+1 );?>" name="tel_number[]" class="text_grv" size="15" maxlength="14" value="<?php echo $telephones[$i]->tel_number;?>"/>
                                            <input type="text" id="tel_ext_<?php echo ( $i+1 );?>" name="tel_ext[]" class="text_grv" size="3" maxlength="5" value="<?php echo $telephones[$i]->tel_ext;?>"/>
										</div>
                                    <?php }?>
                                </div>
                            </td>
                        </tr>
                        <tr>
                        	<td align="right"><span class="lbl_gray">Login:</span></td>
                            <td>&nbsp;</td>
                            <td><input type="text" name="use_login" id="use_login" class="text_grv" size="21" maxlength="20" value="<?php echo $data->use_login;?>" /></td>
                        </tr>
                        <tr>
                        	<td align="right"><span class="lbl_gray">Password:</span></td>
                            <td>&nbsp;</td>
                            <td><input type="password" name="use_password" id="use_password" class="text_grv" size="21" maxlength="20"  /></td>
                        </tr>
                        <tr>
                            <td align="right"><span class="lbl_gray">Confirmar Password:</span></td>
                            <td>&nbsp;</td>
                            <td><input type="password" name="confirm" id="confirm" class="text_grv" size="21" maxlength="20" /></td>
                            <td>&nbsp;</td>
                        </tr>
                        <tr>
                        	<td align="right"><span class="lbl_gray">Tipo de Usuario:</span></td>
                            <td>&nbsp;</td>
                            <td>
                            	<select name="use_type" id="use_type" class="text_grv">
                                    <option value="" selected="selected" disabled="disabled">Seleccione..</option>
                                    <option value="Adviser"<?php if($data->use_type == "Adviser") echo 'selected="selected"'; ?>>Regular</option>
                                    <option value="Admin"<?php if($data->use_type == "Admin") echo 'selected="selected"'; ?>>Admin</option>
                            	</select>
                            </td>
                        </tr>
                        <tr>
                        	<td colspan="3" align="center">&nbsp;</td>
                        </tr>
                        <tr>
                        	<td colspan="3" align="center">
                            <input type="button" class="button_grv" value="Grabar" onclick="javascript: return validate();" />
                             <input type="reset" value="Limpiar" class="button_grv_cancel"/>
                            <input type="button" class="button_grv_cancel" value="Cancelar" onClick="javascript:window.location.href='listUser.php';" /></td>
                        </tr>
                    </table>
                </td>
            </tr>
        </table>
    </div>
</form>    
</body>
</html>
<?php include('divscoolmessage.php');?>